////
////  CodeController.swift
////  SwiftDemo
////
////  Created by lee on 2018/8/21.
////  Copyright © 2018年 mjsfax. All rights reserved.
////
//
//import UIKit
//
///// : 归解档
//@objcMembers
//class Person : NSObject, NSCoding {
//    var name = "";
//    var nickName:String?
//    var age = 0;
//
//    init(name:String = "Tom", nickName:String?="Cat", age:Int = 18) {
//        self.name = name;
//        self.nickName = nickName;
//        self.age = age;
//    }
//
//    //归档
//    func encode(with aCoder: NSCoder) {
//        var count:UInt32 = 0;
//        guard let ivarList = class_copyIvarList(object_getClass(self), &count) else {
//            print("ivarList == nil");
//            return;
//        }
//
//        for i in 0..<Int(count) {
//            let ivar = ivarList[i];
//            guard let cName = ivar_getName(ivar) else {
//                continue;
//            }
//            guard let name = String(utf8String: cName) else {
//                continue;
//            }
//            let value = self.value(forKey: name);
//            aCoder.encode(value, forKey: name);
//        }
//        free(ivarList);
//    }
//    //解档
//    required init?(coder aDecoder: NSCoder) {
//        super.init();
//
//        var count:UInt32 = 0;
//        guard let ivarList = class_copyIvarList(object_getClass(self), &count) else {
//            print("ivarList == nil");
//            return;
//        }
//
//        for i in 0..<Int(count) {
//            let ivar = ivarList[i];
//            guard let cName = ivar_getName(ivar) else {
//                continue;
//            }
//            guard let name = String(utf8String: cName) else {
//                continue;
//            }
//            let value = aDecoder.decodeObject(forKey: name);
//            setValue(value, forKey: name);
//        }
//        free(ivarList);
//    }
//
//}
//
//class CodeController: UIViewController {
//
//    override func viewDidLoad() {
//        super.viewDidLoad()
//
//        let person = Person();
//        let path = "\(NSHomeDirectory())/s_archive.plist";
//        NSKeyedArchiver.archiveRootObject(person, toFile: path);
//
//        let person1 = NSKeyedUnarchiver.unarchiveObject(withFile: path) as? Person;
//        print("name = \(person1?.name ?? ""), nickName = \(String(describing: person1?.nickName))");
//
//        let reflectP = Person();
//        fetchMirror(reflectP);
//
//    }
//
//    /// swift 反射 Mirror struct 获取反射信息
//    func fetchMirror(_ obj:Any) {
//        let mirror = Mirror(reflecting: obj);
//        print("对象类型：\(mirror.subjectType)");
//        print("成员个数：\(mirror.children.count)");
//
//        for case let (key, value) in mirror.children {
//            print("属性：\(String(describing: key)),值：\(value)");
//        }
//    }
//
//}
